package cn.ecnu.paper.controller;



import cn.ecnu.paper.pojo.Author;
import cn.ecnu.paper.service.AuthorService;
import cn.ecnu.paper.vo.AuthorFrontVo;
import cn.ecnu.paper.vo.ViewAuthorVo;
import cn.ecnu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/author")
public class AuthorController {

    @Autowired
    private AuthorService authorService;

    // 获取所有的author
    // TODO: @Own(permission = Permission.ADMIN)
    @GetMapping("/list")
    public R getAuthorList(@RequestParam(value = "pageNum", required = false) Integer pageNum) {
        ViewAuthorVo vo = authorService.getAuthorList(pageNum);
        return R.ok().put("data", vo);
    }

    @GetMapping("/all")
    public R getAuthorList() {
        ViewAuthorVo vo = authorService.getAuthorAllList();
        return R.ok().put("data", vo);
    }

    // 添加作者
    // TODO: @Own(permission = Permission.VIEW)
    @PostMapping("/add")
    public R addAuthor(@RequestBody AuthorFrontVo vo) {
        Author author = authorService.addAuthor(vo);
        return R.ok().put("data", author);
    }

}
